// JavaScript Document
define(function (require, exports, module) {
	var Page=require("Page");
	var SearchForm=require("SearchForm");
	var ListForm=require("ListForm");
	
	ListPage = function(){
	};
	ListPage.prototype=new Page();
	ListPage.prototype.target="";
	
	ListPage.prototype.baseInit=function(element){
		Page.prototype.baseInit.call(this,element);
		this.searchForm=new SearchForm(this.target);
		this.searchForm.init();
		
		
		this.listForm=new ListForm();
		this.listForm.init();
		
		//因二次绑定所以把loading 放入判断中
		if(typeof element=="undefined"){
			try{
				this.cloneParaModule()
			}catch(error){
				console.log(error);
			}
		}
		
		ht.loading.close();
	}
	ListPage.reload=function(){
		ListForm.reload();
	}
	ListPage.prototype.clearZeroHref=function(selector){
		$(selector+" a").each(function(){
			var text=$(this).text();
			if(text=="0"){
				$(this).removeAttr("href");
			}
		})
	}
	ListPage.prototype.setNoneRecordBySelector=function(selector){
		//noResults
		var listModule = $(selector).get(0);
		if(listModule==null || typeof listModule =="undefined"){
			return false;
		}
		var x = listModule.getElementsByTagName('tbody')[0].children.length;
		if( x == 0)
		{
			var divElement;
			divElement = document.createElement("div")
			divElement.className="noneRecord"
			divElement.innerHTML=("查无记录！")
			listModule.appendChild(divElement)
			
			var pagination = document.getElementById("pagination")
			if(pagination)
			{
				pagination.style.display="none";
			}
		}
	}
	//克隆参数模块
	ListPage.prototype.cloneParaModule=function(){
		
		var serializeArray,paraModule,element,searchForm,listForm;
		
		//添加列表辅助数据
		serializeArray=this.searchForm.getSerializeArray();
		
		paraModule=new ParaModule(serializeArray);
		element=paraModule.getElement();
		
		this.listForm.insertElement(element);
		
		
		
		//添加上搜索表单辅助数据
		serializeArray=this.listForm.getOrderSerializeArray();
		
		paraModule=new ParaModule(serializeArray);
		element=paraModule.getElement();

		this.searchForm.insertElement(element);
	}
	//参数模块
	var ParaModule=function(serializeArray){
		this.serializeArray=serializeArray
	}
	ParaModule.prototype.getElement=function(){
		var element,name,value,inputElement,html;
		
		element=document.createElement("div");
		element.className="module paraModule"
		for(var i in this.serializeArray){
			name=this.serializeArray[i].name;
			value=this.serializeArray[i].value;
			html="<input type=\"hidden\" name=\""+name+"\" value=\""+value+"\" />" //不使用node.name='aa'方式，避免低版本ie转化为submitName属性
			inputElement=$(html).get(0)
			element.appendChild(inputElement);
		}
		
		inputElement=document.createElement("input");
		inputElement.type="submit"
		element.appendChild(inputElement);
		
		return element;
	}
	window.reload=ListPage.reload;
	module.exports = ListPage;
});